Purpose
The lastIndexOf string task allows users to identify the last occurrence of a specific character or group of characters within a given string. It is similar to the indexOf task, with the exception that it begins searching from the end of the input string (rather than the beginning). In other words, the search is backwards starting from a position identified by the fromIndex value. This method returns a number (index) that represents the position where the specified search value occurs.
Note: The lastIndexOf task does not change the value of the original string.
Potential Use Case
Let's say you have a string that contains a date within it, and you need to locate the last slash "/" in the date value so that you can isolate the position of the "year" value. You could potentially use the lastIndexOf task and extract it in a subsequent slice or substring task.
Properties
| Incoming | Type | Description |
|---|---|---|
str |
String | Required. The string that contains the searchValue to be located. |
searchValue |
String | Required. The value to search for in the str. |
fromIndex |
Number | Optional. The position in the string to begin the search. Leaving this value empty will default to the end of the str and the full string is searched. When counting characters in a string, indexing begins at position '0' (the first str value). If the fromIndex value is greater than zero, the search will begin to the left of that specified index position. If '0' or a number less than '0', only the first character in the string will be considered and then search the string backwards from there. |
| Outgoing | Type | Description |
|---|---|---|
index |
Number | The position in the str where the searchValue was first identified. If the searchValue is not found in the specified str, the index property will return -1. |
Examples
Example 1
In this IAP example:
The
strvariable has been statically set assales.department@itential.com.The
searchValuevariable has been statically set as"."(a period).The
fromIndexvariable has been intentionally left empty, indicating the search should start at the end of thestrvalue.The output
indexvalue will be25because the first instance of a period".", starting from the end of the string, can be found at character position 25 (counting from the left) in thestrvariable.
Example 2
In this IAP example:
The
strvariable has been statically set assales.department@itential.com.The
searchValuevariable has been statically set as"."(a period).The
fromIndexvariable has been set to20(a random number selected for demo purposes), indicating the search should start at position 20 of thestrvalue and proceed to the left of that starting index position.The output
indexvalue will be5because the first instance of a period".", starting left from position 20, can be found at character position 5 in thestrvariable.
Example 3
In this IAP example:
The
strvariable has been statically set assales.department@itential.com.The
searchValuevariable has been statically set as"Z".The
fromIndexvariable has been intentionally left empty, indicating the search should start at the end of thestrvalue.The output
indexvalue will be-1, because there is no"Z"in thestrvalue.
Example 4
In this IAP example:
The
strvariable has been statically set assales.department@itential.com.The
searchValuevariable has been statically set as"s".The
fromIndexvariable has been set to-100(a random number selected for demo purposes). Since negative numbers are considered as a '0', the search will begin at the first letter of thestrvalue.The output
indexvalue will be0in reference to the first letter of thestrvalue, which is the letter"s".